<?php get_instance()->view('common/header');?>
<!--<script src="--><?php //echo $this->staticUrl;?><!--plugins/dist/js/app.js" type="text/javascript"></script>-->
<style>
	.box.box-info {
		border-top-color: #e6e6e6;
	}
	.box-header.with-border {
		border-bottom: 1px solid #f4f4f4;
	}
	.box-body {
		border-top-left-radius: 0;
		border-top-right-radius: 0;
		border-bottom-right-radius: 3px;
		border-bottom-left-radius: 3px;
		padding: 10px;
	}
	.box-header {
		color: #444;
		display: block;
		padding: 10px;
		position: relative;
	}
	.box.box-primary {
		border-top-color: #e6e6e6;
	}
	.box {
		position: relative;
		border-radius: 3px;
		background: #ffffff;
		border-top: 3px solid #d2d6de;
		margin-bottom: 20px;
		width: 100%;
		box-shadow: 0 1px 1px rgba(0,0,0,0.1);
	}
    #list-table>thead>tr>th{text-align: center;}

</style>
<div class="page-container wrapper">
	<!-- BEGIN SIDEBAR -->
    <?php get_instance()->view('common/sidebar');?>
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content" style="min-height:1200px !important">
			<!-- BEGIN PAGE HEADER-->
			<div class="col-xs-12">
				<div class="">
					<div class="row">
						<div class="col-md-12">
							<div class="box box-info">
								<div class="box-header with-border">
									<div class="row">
										<div class="col-md-12">
											<form action="" method="post">
												<div class="col-xs-5">
													<div class="input-group margin">
														<div class="input-group-addon">
															选择时间  <i class="fa fa-calendar"></i>
														</div>
														<input type="text" class="form-control pull-right" name="timegap" value="<?php echo $startTime .' - '. $endTime?>" id="start_time">
													</div>
                                                    <span class="help-block">温馨提示：选择的时间范围请控制在三个月以内,若超过范围则自动计算时间</span>
												</div>
												<!--<div class="col-xs-2">-->
													<!--<div class="input-group margin">-->
														<!--<div class="input-group-addon">-->
															<!--选择商家-->
														<!--</div>-->
														<!--<select name="s_uid" class=" form-control input-inline input-small input-sm">-->
															<!--<option value=""><?php echo '所有';?></option>-->
															<!--<volist name="shang" id="v">-->
																<!--<option value="{$v.s_uid}" <if condition="$s_uid eq $v['s_uid']">selected='selected'</if>>{$v.shang_name}</option>-->
															<!--</volist>-->
														<!--</select>-->
													<!--</div>-->
												<!--</div>-->
                                                <?php if(adminAuthority('sell-export', 'statistics')):?>
                                                    <div class="col-xs-2 col-xs-offset-3"><a class="btn btn-block export blue" href="javascript:;">导出</a></div>
                                                    <div class="col-xs-2 "><input class="btn btn-block btn-info green" type="submit" value="确定"></div>
                                                <?php else:?>
                                                    <div class="col-xs-2 col-xs-offset-5"><input class="btn btn-block btn-info green" type="submit" value="确定"></div>
                                                <?php endif;?>
											</form>
										</div>
									</div>
								</div>
								<div class="box-body">
									<div class="row">
										<div class="col-sm-3 col-xs-6">
											今日销售总额：￥<?php echo $sameDay['amount']?></empty>
										</div>
										<div class="col-sm-3 col-xs-6">
											人均客单价：￥<?php echo $sameDay['sign']?>
										</div>
										<div class="col-sm-3 col-xs-6">
											今日订单数：<?php echo $sameDay['order_num']?>
										</div>
										<div class="col-sm-3 col-xs-6">
											今日交易关闭订单：<?php echo $cancelOrder?>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="box box-primary">
								<div class="box-header with-border">
									<h3 class="panel-title">销售额走势</h3>
									<div class="box-tools"></div>
									<div class="box-tools pull-right" style="display: none">
										<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
										<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
									</div>
								</div>
								<div class="box-body">
									<div class="chart" style="height: 400px;">
										<div id="statistics" style="height: 400px;"></div>
									</div>
								</div>
							</div>
						</div>
					</div>

					<div class="row">
						<div class="col-sm-12">
							<div class="panel panel-default">
								<div class="panel-heading">
									<h3 class="panel-title"><i class="fa fa-list"></i> 销售表格概览</h3>
								</div>
								<div class="panel-body">
									<table id="list-table" class="table table-bordered table-striped">
										<thead>
										<tr>
											<th>时间</th>
											<th>销售总额</th>
											<th>客单价</th>
											<th>订单数</th>
											<th>查看</th>
										</tr>
										</thead>
										<tbody>
                                        <?php foreach ($list as $k => $v):?>
											<tr role="row" align="center">
												<td><?php echo $v['time']?></td>
												<td><?php echo $v['amount']?></td>
												<td><?php echo $v['sign']?></td>
												<td><?php echo $v['order_num']?></td>
												<td>
                                                    <a href="<?php echo getUrl('statistics/sell/saleList?time='.$v['time'])?>" class="btn btn-xs green-stripe default">查看订单</a>&nbsp;
												</td>
											</tr>
                                        <?php endforeach;?>
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- END CONTENT -->
</div>
<script type="text/javascript">
	var res = <?php echo $result?>;
	var myChart = echarts.init(document.getElementById('statistics'),'macarons');
	option = {
		tooltip : {
			trigger: 'axis'
		},
		toolbox: {
			show : true,
			feature : {
				mark : {show: true},
				dataView : {show: true, readOnly: false},
				magicType: {show: true, type: ['line', 'bar']},
				restore : {show: true},
				saveAsImage : {show: true}
			}
		},
		calculable : true,
		legend: {
			data:['交易金额','订单数','客单价']
		},
		xAxis : [
			{
				type : 'category',
				data : res.time
			}
		],
		yAxis : [
			{
				type : 'value',
				name : '金额',
				axisLabel : {
					formatter: '{value} ￥'
				}
			},
			{
				type : 'value',
				name : '客单价',
				axisLabel : {
					formatter: '{value} ￥'
				}
			}
		],
		series : [

			{
				name:'交易金额',
				type:'bar',
				data:res.amount
			},
			{
				name:'订单数',
				type:'bar',
				data:res.order
			},
			{
				name:'客单价',
				type:'line',
				yAxisIndex: 1,
				data:res.sign
			}
		]
	};
	myChart.setOption(option);
        
	$(document).ready(function() {
		$('#start_time').daterangepicker({
			format:"YYYY-MM-DD",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2016-01-01',
            maxDate: moment(new Date()), //设置最大日期
			startDate:'<?php echo $startTime?>',
            endDate: '<?php echo $endTime?>', //设置结束器日期
			showWeekNumbers: true,
			timePicker: false,
			timePickerIncrement: 1,
			timePicker12Hour: true,
			ranges: {
				'今天': [moment(), moment()],
				'昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
				'最近7天': [moment().subtract('days', 6), moment()],
				'最近30天': [moment().subtract('days', 29), moment()],
				'上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
			},
			opens: 'right',
			buttonClasses: ['btn btn-default'],
			applyClass: 'btn-small btn-primary',
			cancelClass: 'btn-small',
			locale : {
				applyLabel : '确定',
				cancelLabel : '取消',
				fromLabel : '起始时间',
				toLabel : '结束时间',
				customRangeLabel : '自定义',
				daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
				monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
				firstDay : 1
			}
		});
	});
	
	$(function () {
        $(".export").click(function () {
            var time = $("[name='timegap']").val();
            window.location.href = "<?php echo getUrl('statistics/sell/export?time=')?>"+time
        })
    })
</script>
</body>
</html>